<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="../js/vue.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="root">
        <h1 :style="{opacity}">Vue生命周期</h1>
        <button @click="del">销毁VM</button>
    </div>

    <script>
        new Vue({
            el: '#root',
            data: {
                opacity: 1
            },
            methods: {
                del() {
                    console.log('销毁vm11111')
                    this.$destroy()
                    console.log('销毁vm12222')
                }
            },
            beforeCreate() {
                console.log('beforeCreate');
            },
            created() {
                console.log('created')
            },
            beforeMount() {
                console.log('beforeMount')
            },
            mounted() {
                console.log('mounted')
                this.timer = setInterval(() => {
                    console.log('setInterval')
                    if (this.opacity <= 0) {
                        this.opacity = 1;
                    } else {
                        this.opacity -= 0.1
                    }
                }, 100)
            },
            beforeUpdate() {
                console.log('beforeUpdate')
            },
            updated() {
                console.log('updated')
            },
            beforeDestroy() {
                console.log('beforDestory')
                clearInterval(this.timer)
            },
            destroyed() {
                console.log('destroyed')
            }
        })
    </script>
</body>
</html>